<template>
	<view class="codepage">
		<canvas class="qrcode top1" canvas-id="qrcode"></canvas>
		<img class="qrcode" :src="img" alt="">
		
		<button type="default">请长按图片保存</button>
	</view>
</template>
<script>
	import {
		myInfo
	} from '../../request/api.js'
	import uQRCode from '@/components/Sansnn-uQRCode/uqrcode.js'
	export default {
		data() {
			return {
				img: '',
			}
		},
		onLoad(options) {
			myInfo().then(res => {
				if (res.code === 200) {
					this.make(res.data.url)
				}
			})
		},
		methods: {
			make(companyurl) {
				// 生成二维码 回调方式
				uQRCode.make({
					canvasId: 'qrcode',
					componentInstance: this,
					text: companyurl,
					size: 130,
					margin: 10,
					backgroundColor: '#ffffff',
					foregroundColor: '#000000',
					fileType: 'jpg',
					correctLevel: uQRCode.errorCorrectLevel.H,
					success: res => {
						this.img = res
					},
					fail(err) {
						console.log(err, '==============')
					}
				})
			},
		}
	}
</script>

<style scoped lang="less">
	.codepage {
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
		overflow: auto;

		.qrcode {
			width: 130px;
			height: 130px;
			margin: 50upx auto;
			display: block;
			background-color: #FFFFFF;
		}
		.top1{
			position: absolute;
			top: -500upx;
		}
		button {
			width: 630upx;
			height: 88upx;
			line-height: 88upx;
			background: #F86C53;
			border-radius: 44upx;
			color: #FFFFFF;
			font-size: 36upx;
			font-family: Source Han Sans CN;
			font-weight: 500;
		}

		button:after {
			border: none;
		}
		
		
	}
</style>
